import { restService } from '@/apis/rest';
import { RootState } from '@/store';
import MultiWebSocket, { ConnectionInfo, IMultiWebSocket } from '@/utils/websocket';
import { Module } from 'vuex';
import { frontAside } from './Aside';
import { frontHeader } from './Header';
import { frontMain } from './Main';
import { IHomeActions, IHomeGetter, IHomeMutations, IHomeState } from './types';

const state: IHomeState = {
    wsQueue: new MultiWebSocket() as unknown as IMultiWebSocket,
}

const actions: IHomeActions = {

}
const mutations: IHomeMutations = {
 
    _addWebsocket(state: IHomeState, { id, connectionInfo }: { id: string, connectionInfo: ConnectionInfo }) {
        state.wsQueue.addConnection(id, connectionInfo);
    },
    _removeWebsocket(state: IHomeState, id: string) {
        state.wsQueue.removeConnection(id);
    },
    _setWebsocket(state: IHomeState, { id, message }: { id: string, message: string | ArrayBuffer }) {
        state.wsQueue.setMessageQueue(id, message);
    },

    // 重置HomeStoreState
    _resetHomeStoreState(state: IHomeState) {
        // state.headerState.routes.length = 0;
        // state.headerState = {
        //     logo: '',
        //     title: '',
        //     subTitle: '',
        //     routes: [],
        //     performance: { time: '', CPU: '', Mem: '' }
        // } as IHomeState['headerState'];
    }
}
const getters: IHomeGetter = {
}

export const home: Module<IHomeState, RootState> = {
    namespaced: true,
    state,
    actions,
    mutations,
    getters,
    modules: {
        frontHeader,
        frontAside,
        frontMain
    }
}